from apps.merchant.coupon.baseViews import *

class CouponViewForUserCartSet(BaseCouponViewSet):

    def get_queryset(self):
        params = getRequestParams(self.request)
        _list = CouponDao().findAll().select_related('user')
        return _list

    # 查询可用立减券
    @action(methods=['post'], detail=False)
    def defaultDiscountCoupon(self, request):
        params = getRequestParams(request)
        realPay = Decimal(params.get('realPay'))
        _coupons = CouponDao().findAll().filter(user=request.user, types='2',status='wait_use',fullMoney__lt=realPay).order_by('-fullMoney')
        if _coupons.exists():
            return Response(response_success(CouponModelSerializer(_coupons[0]).data))
        else:
            return Response(response_action(10001, '没有可用立减券'))

